package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.util.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(value = "用户controller", description = "用户操作", tags = {"用户操作接口"})
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("获取用户信息")
//    @RequestMapping("/showUser")
    @PostMapping("/showUser")
    @ResponseBody
    public Result<User> toIndex(@RequestBody Map<String, Object> params) {
//        int userId = Integer.parseInt(request.getParameter("id"));
        User user = this.userService.getUserById((Integer) params.get("id"));
        return Result.success(user);
    }

    @ApiOperation("获取用户信息")
    @RequestMapping("/showUser")
    @ResponseBody
    public String login(HttpServletRequest request, Model model) {

        return null;
    }

}